package sany.iec.service.schedule;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import sany.iec.config.GlobalVariable;
import sany.iec.enums.EnableEnum;

import java.io.IOException;
import java.util.UUID;

/**
 * @Author : 托马斯
 * @Date : 2025/7/8 8:37
 * @Description :
 */
@Service
@Slf4j
public class ImportantInfoSchedule {

    @Scheduled(initialDelay = 5000, fixedRate = 300000)
    public void schedule() {
        UUID uuid = UUID.randomUUID();
        log.info(" ------------------  重要信息开始 {} ---------------------", uuid);
        log.info("缓存共有数据: {}条。", GlobalVariable.GLOBAL_MAP.size());
        GlobalVariable.SERVER_LIST.forEach(server -> {
            log.info("table: {}, 协议: {}, 端口: {}, modbusId:{}, 是否启动: {}。", server.getTableName(),
                    server.getServerType().getType(), server.getPort(),
                    server.getModbusId(), server.getEnable().getFlag());
            if (server.getModbusServerSet() == null && server.getIEC104Server() == null) {
                log.warn("该服务已经关闭。{} {}", server.getTableName(), server.getPort());
            } else {
                int num = 0;
                for (String key : GlobalVariable.GLOBAL_MAP.keySet()) {
                    if (key.contains(server.getPort().toString())) {
                        num++;
                    }
                }
                log.info("{} 共有 {} 点在缓存。", server.getTableName(), num);
            }
        });
        log.info(" ------------------  重要信息结束 {} ---------------------", uuid);
    }

}
